package com.tencreat.account.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.account.AccountLoginCheck;
import com.tencreat.service.account.IAccountLoginCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 登录 用户类型Controller
 *
 * @author tencreat
 * @date 2021-09-06
 */
@Api(tags="登录 用户类型api")
@RestController
@RequestMapping("/system/check")
public class AdminAccountLoginCheckController extends BaseController {
    @Autowired
    private IAccountLoginCheckService accountLoginCheckService;

    /**
     * 查询登录 用户类型列表
     */
    @ApiOperation(value="查询登录 用户类型列表")
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @PostMapping("/list")
    public HttpResult<IPage<AccountLoginCheck>> list(@RequestBody  AccountLoginCheck accountLoginCheck) {
        QueryWrapper<AccountLoginCheck> wrapper = Wrappers.query(accountLoginCheck);
        Page<AccountLoginCheck> page =  new Page<>(accountLoginCheck.getPageNum(), accountLoginCheck.getPageSize());
        return HttpResult.ok(accountLoginCheckService.page(page, wrapper));
    }

    /**
     * 导出登录 用户类型列表
     */
    @ApiOperation(value="导出登录 用户类型列表")
    @PreAuthorize("@ss.hasPermi('system:check:export')")
    @Log(title = "登录 用户类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(AccountLoginCheck accountLoginCheck) {
        List<AccountLoginCheck> list = accountLoginCheckService.selectAccountLoginCheckList(accountLoginCheck);
        ExcelUtil<AccountLoginCheck> util = new ExcelUtil<AccountLoginCheck>(AccountLoginCheck.class);
        return util.exportExcel(list, "check");
    }

    /**
     * 获取登录 用户类型详细信息
     */
    @ApiOperation(value="获取登录 用户类型详细信息")
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<AccountLoginCheck> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(accountLoginCheckService.selectAccountLoginCheckById(id));
    }

    /**
     * 新增登录 用户类型
     */
    @ApiOperation(value="新增登录 用户类型")
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "登录 用户类型", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  AccountLoginCheck accountLoginCheck) {
        return to(accountLoginCheckService.insertAccountLoginCheck(accountLoginCheck));
    }

    /**
     * 修改登录 用户类型
     */
    @ApiOperation(value="修改登录 用户类型")
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "登录 用户类型", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  AccountLoginCheck accountLoginCheck) {
        return to(accountLoginCheckService.updateAccountLoginCheck(accountLoginCheck));
    }

    /**
     * 删除登录 用户类型
     */
    @ApiOperation(value="删除登录 用户类型")
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "登录 用户类型", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(accountLoginCheckService.deleteAccountLoginCheckByIds(ids));
    }
}
